//
//  JQFYMusicGenreCell.m
//  JQFY
//
//  Created by 代辉 on 2017/10/30.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYMusicGenreCell.h"
#import "JQFYMusicGenreCollectionViewCell.h"

@interface JQFYMusicGenreCell () <UICollectionViewDelegate,UICollectionViewDataSource>

@end

static NSString *_MUSIC_GENRE_CELL_ = @"_MUSIC_GENRE_CELL_";
UICollectionView *_collection;
@implementation JQFYMusicGenreCell {
    UICollectionView *_collection;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = [UIColor clearColor];
    UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
    flowLayout.itemSize = CGSizeMake(236 *0.5 *SCAL, 129 *0.5 *SCAL);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    _collection = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    [self.contentView addSubview:_collection];
    _collection.backgroundColor = [UIColor clearColor];
    _collection.showsHorizontalScrollIndicator = NO;
    [_collection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    _collection.contentInset = UIEdgeInsetsMake(0, 10 *SCAL, 0, 10 *SCAL);
    [_collection registerClass:[JQFYMusicGenreCollectionViewCell class] forCellWithReuseIdentifier:_MUSIC_GENRE_CELL_];
    _collection.delegate = self;
    _collection.dataSource = self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.songInfo.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    JQFYMusicGenreCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:_MUSIC_GENRE_CELL_ forIndexPath:indexPath];
    cell.songInfo = self.songInfo[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"clickMore" object:@(0)];
}
- (void)setSongInfo:(NSArray *)songInfo
{
    _songInfo = songInfo;
    [_collection reloadData];
}
@end
